<style>
.pure_form_extra3 { background: #fff; padding: 2px; border: 1px solid #aaa; border-radius: 3px; }
.pure_form_extra3 span { font-size: 12px !important; color: #666; font-family: Trebuchet MS; }
.pure_form_extra3 a { font-size: 13px !important; color: #666; font-family: Trebuchet MS; }
</style>
<?php
$SIZE = 10;

if ($cat != 0) {
  $opts = new stdClass();
  $opts->cd = 't.categories__ LIKE :v1';
  $opts->cdv = array(':v1' => '%,' . $cat . ',%');
  $pops = $orm->get('pb_ht_article', 't.visited__', 'DESC', 1, $SIZE, $opts)->d;
  $lats = $orm->get('pb_ht_article', 't.date', 'DESC', 1, $SIZE, $opts)->d;
} else {
  $pops = $orm->get('pb_ht_article', 't.visited__', 'DESC', 1, $SIZE, NULL)->d;
  $lats = $orm->get('pb_ht_article', 't.date', 'DESC', 1, $SIZE, NULL)->d;
}

?>
<div>&nbsp;</div>
<div class="pure-form pure_form_extra3 il2" style="padding-right: 5px;">
  <div style="padding: 5px 10px; font-size: 13px; font-weight: bold; background: #fff008;">最受欢迎 Top10</div>
  <table class="pure-table pure_table_extra_ab" cellPadding="0" cellSpacing="0">
    <?php foreach ($pops as $idx => &$itm) { ?>
    <tr class="<?php echo ($idx % 2 == 0) ? 'pure-table-even' : 'pure-table-odd'; ?>">
      <td>
        <span class="date"><?php echo date('Y-m-d', strtotime($itm->date)); ?></span>
        <a href="#" onclick="return Url.redirect(__redmd, __sys + '.php?i=' + __id + '&__file=index_article&id=<?php echo $itm->id?>&cat=<?php echo $cat?>');"><?php echo Utils::get_short($itm->title, 15);?></a>
      </td>
    </tr>
    <?php } ?>
    <?php for ($i = 10 - count($pops), $il = 0; $i > $il; $i--) { ?>
    <tr class="<?php echo ($i % 2 == 0) ? 'pure-table-even' : 'pure-table-odd'; ?>"><td>&nbsp;</td></tr>
    <?php } ?>
  </table>
</div>

<div class="pure-form pure_form_extra3 il2" style="padding-right: 5px;">
  <div style="padding: 5px 10px; font-size: 13px; font-weight: bold; background: #34fc13;">最新更新 Top10</div>
  <table class="pure-table pure_table_extra_ab" cellPadding="0" cellSpacing="0">
    <?php foreach ($lats as $idx => &$itm) { ?>
    <tr class="<?php echo ($idx % 2 == 0) ? 'pure-table-even' : 'pure-table-odd'; ?>">
      <td>
        <span class="date"><?php echo date('Y-m-d', strtotime($itm->date)); ?></span>
        <a href="#" onclick="return Url.redirect(__redmd, __sys + '.php?i=' + __id + '&__file=index_article&id=<?php echo $itm->id?>&cat=<?php echo $cat?>');"><?php echo Utils::get_short($itm->title, 15);?></a>
      </td>
    </tr>
    <?php } ?>
    <?php for ($i = 10 - count($lats), $il = 0; $i > $il; $i--) { ?>
    <tr class="<?php echo ($i % 2 == 0) ? 'pure-table-even' : 'pure-table-odd'; ?>"><td>&nbsp;</td></tr>
    <?php } ?>
  </table>
</div>

<div class="pure-form pure_form_extra3 il2">
  <div style="padding: 5px 10px; font-size: 13px; font-weight: bold; background: #3da6ff;">最近浏览</div>
  <table class="pure-table pure_table_extra_ab" cellPadding="0" cellSpacing="0">
    <tbody id="a_browsed"></tbody>
  </table>
</div>

<script type="text/javascript">
  var __cat = '<?php echo $cat; ?>';
  var __requrl = '<?php echo Utils::get_requrl($app_data); ?>';
  var __redmd = '<?php echo addslashes($app_data->sys->redmd); ?>';
  var __sys = '<?php echo addslashes($app_data->sys->php_name); ?>';
  var __id = '<?php echo $app_data->param_id; ?>';
  var __browsed;
  
  $(function(){
    __browsed = Cookie.get_cookie('a_browsed');
    if (!__browsed) {
      __browsed = [];
    } else {
      __browsed = JSON.parse(__browsed);
    }
    
    render_browsed();
  });
  
  function render_browsed() {
    $('#a_browsed').empty();
    for (var idx in __browsed) {
      var itm = __browsed[idx];
      $('#a_browsed').append(
        '<tr class="' + ((idx % 2 == 0) ? 'pure-table-even' : 'pure-table-odd') + '">' +
          '<td>' +
            '<span class="date">' + itm.date.split(' ')[0] + '</span>' +
            '<a href="#" onclick="return Url.redirect(__redmd, \'' + __sys + '.php?i=' + __id + '&__file=index_article&id=' + itm.id + '&cat=' + itm.__cat + '\');">' + Utils.get_short(itm.title, 15) + '</a>' +
          '</td>' +
        '</tr>'
      );
    }
    for (var i = 9 - __browsed.length, il = 0; i > il; i--) {
      var itm = __browsed[idx];
      $('#a_browsed').append('<tr class="' + ((i % 2 == 1) ? 'pure-table-even' : 'pure-table-odd') + '"><td>&nbsp;</td></tr>');
    }
    $('#a_browsed').append('<tr class="pure-table-odd"><td style="text-align: right;"><a href="#" onclick="Cookie.set_cookie(\'a_browsed\', \'[]\', -1); __browsed = []; render_browsed(); return false;">清除</a></td></tr>');
  };
</script>
